#define  _CRT_SECURE_NO_WARNINGS 


#include<stdio.h>
#include<string.h>
#include<assert.h>





int main5()
{
	char buffer1[] = "DWgaOtP12df0";
	char buffer2[] = "DWGAOTP12DF0";

	int n;

	n = memcmp(buffer1, buffer2, sizeof(buffer1));

	if (n > 0) 
		printf("'%s' is greater than '%s'.\n", buffer1, buffer2);
	else if (n < 0) 
		printf("'%s' is less than '%s'.\n", buffer1, buffer2);
	else 
		printf("'%s' is the same as '%s'.\n", buffer1, buffer2);

	return 0;
}


void* my_memset(void* des, int ptr, size_t num)
{
	assert(des);
	void* ret = des;

	int i = 0;
	while (num--)
	{
		*((char*)des+i) = (char)ptr;
		i++;
	}
	return ret;
}

int main4()
{
	char arr1[] = "abcdef";
	my_memset(arr1, 'x', 3);
	printf("%s\n", arr1);

	char arr2[] = "abcdef";
	my_memset(arr2, 65, 4);
	printf("%s\n",arr2);

	int arr3[] = { 1,2,3,4,5 };
	my_memset(arr3,7,4);
	printf("%d\n", arr3[0]);
	return 0;
}

void* my_memmove(void* des, void* src, size_t num)
{
	assert(des && src);
	void* ret = des;

	if (des < src)
	{
		int i = 0;
		while (num--)
		{
			*((char*)des + i) = *((char*)src + i);
			i++;
		}
	}
	else
	{
		while (num--)
		{
			*((char*)des + num) = *((char*)src + num);
		}
	}
	return ret;
}

int main3()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	my_memmove(arr, arr+2, 16);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}

void* my_memcpy(void* des, const void* src,size_t num)
{
	void* ret = des;
	assert(des && src);

	int i = 0;
	while (num--)
	{
		*((char*)des + i) = *((char*)src + i);
		i++;
	}

	return ret;
}

int main2()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	memcpy(arr+2, arr, 16);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}


int main1()
{
	char arr1[] = "abcdef";
	char arr2[30] = { 0 };
	my_memcpy(arr2, arr1, 4);
	printf("%s ", arr2);
	return 0;
}

int main0()
{
	int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };
	int arr2[30] = { 0 };
	memcpy(arr2, arr1, 20);
	for (int i = 0; i < 30; i++)
	{
		printf("%d ",arr2[i]);
	}
	return 0;
}